<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%
String path = request.getContextPath();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title></title>
  </head>
  <script>
  function cardLevelAdd_submit(obj){
  	if ($("#sel_level").val()==""){
  		alert("请选择会员卡级别！");
  		return false;
  	}
  	$("input[name='cardLevelVO.customerVO.id']").val($("#customerId").val());
  	return validateCallback(obj, navTabAjaxDone);
  }
  function changeCustomer(customerId){
  	$.ajax({cache:false, url:"${pageContext.request.contextPath}/ajax/ajaxGetLevelByCustomer.do", type:"post", dataType:"json", data:{customerId:customerId}, success:showLevel});
  }
  function showLevel(json){
  	var allLevel = new Array();
  	for (var i = 1; i <= 20; i++) {
  		allLevel.push(i);
  	}
  	for (var i in json) {
  		allLevel.splice($.inArray(parseInt(json[i].level),allLevel),1);
  	}
  	$("#sel_level").empty();
  	var oStr = "<option value='' select='true'>请选择</option>";
  	for (var i in allLevel) {
  		oStr += "<option value='"+allLevel[i]+"'>"+allLevel[i]+"</option>";
  	}
  	$(oStr).appendTo($("#sel_level"));
  	$("#p_level").css("display","block");
  }
  </script>
  <body>
	<div class="pageContent">
		<form method="post" action="<%=path %>/cardLevel/saveCardLevel.action" class="pageForm required-validate" onsubmit="return cardLevelAdd_submit(this);">
			<div class="pageFormContent" layoutH="56">
				<p>
					<label>级别名：</label>
					<input name="cardLevelVO.levelName" value="<s:property value="cardLevelVO.levelName" />" class="required" type="text" size="30" alt="请输入级别名"/>
				</p>
				<p>
					<label>所属商家：</label>
					<input id="customerId" name="customerId" value="${SESSION_USER.customer==null?'':(SESSION_USER.customer.id)}" type="hidden" size="30"/>
					<input name="cardLevelVO.customerVO.id" value="${SESSION_USER.customer==null?'':(SESSION_USER.customer.id)}" type="hidden">
					<input id="customerName" name="customerName" value="${SESSION_USER.customer==null?'':(SESSION_USER.customer.name)}" class="required" readonly>
					<c:if test="${SESSION_USER.customer==null}">
						<a class="btnLook" href="<%=path %>/customer/listCustomer.action?searchType=cardLevel" lookupGroup="">选择</a>
					</c:if>
				</p>
				<p style="display: none" id="p_level">
					<label>可选级别：</label>
					<select name="cardLevelVO.level" id="sel_level"></select>
				</p>
			</div>
			<div class="formBar">
				<ul>
					<li><div class="buttonActive"><div class="buttonContent"><button type="submit">保存</button></div></div></li>
					<li>
						<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
					</li>
				</ul>
			</div>
		</form>
	</div>
  </body>
</html>